home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap2 / 2_2 / testserv.pl < prev    next >
Encoding:
Perl Script  |  1996-06-15  |  1.0 KB  |  59 lines

  1. #!/usr/bin/perl
  2.  
  3. # Access the environment variable by name
  4.  
  5. $server_name = $ENV{'SERVER_NAME'};
  6.  
  7. # Store the server port number
  8.  
  9. $server_port = $ENV{'SERVER_PORT'};
  10.  
  11. # Send the output mime type to the server to expect HTML output
  12.  
  13. print "Content-type: text/html\n\n";
  14.  
  15. # Print required HTML tags.
  16.  
  17. print <<EOH;
  18. <HTML>
  19. <HEAD><TITLE>CGI Script How-To: Test Script</TITLE></HEAD>
  20. <BODY>
  21. EOH
  22.  
  23. print "<H1>CGI Script How-to<BR>determine the server's name for self referencing URL's</H1>\n";
  24.  
  25. if ($server_name)
  26. {
  27.  # Define a self-referencing URL to the server's home page
  28.  
  29.     $url = "http://" . $server_name;
  30.  
  31. # Check the port number.
  32.  
  33.     if ($server_port && $server_port != 80)
  34.     {
  35.         $url .= ":$server_port";
  36.     }
  37.  
  38. # Add the closing slash to terminate the URL
  39.  
  40.     $url .= "/";
  41.  
  42. # Print the hyperlinked URL to the home page
  43.  
  44.     print "<H2>You can go to the home page of this server with the URL:\n";
  45.     print qq!<A HREF="$url">$url</A></H2>\n!;
  46. }
  47. else
  48. {
  49.         print "<H2>Server cannot be determined</H2>\n";
  50. }
  51.  
  52. # Print closing HTML tags
  53.  
  54. print "</BODY></HTML>\n";
  55.  
  56. #
  57. # end of testserv.pl
  58. #
  59.